-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more types for Random (fix conflict #470) #1144
Conversation
core/random.rbs
Outdated
@@ -71,6 +91,7 @@ class Random < RBS::Unnamed::Random_Base | |||
def self.rand: () -> Float | |||
| (Integer | ::Range[Integer] max) -> Integer | |||
| (Float | ::Range[Float] max) -> Float | |||
| (::Range[T]) -> T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the type we want would be [T <: Numeric] (Range[T]) -> T, but RBS currently doesn't allow writing it.
I think there are two options. [T] (Range[T]) -> T or (Range[Numeric]) -> Numeric. The first option would make sense in my opinion, because testing the code will uncover the problem anyway.
#470 (comment)
Is [T] (Range[T])
invalid syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[T] (Range[T])
is not a valid piece of code. It becomes a valid method type by adding the returned type, like [T] (Range[T]) -> T
as soutaro said.
By the way, [T < Numeric] (Range[T]) -> T
is more appropriate because the upper bound type for a type parameter has been implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 👍
original pull request is #470
What I do
Why I do
I need changesets of the #470 (especially
Random.urandom
) but original author did not respond mainteiner's review comments from 2 years.